import store from '@/store/index.js'

/**
 * 获取字典
 * 
 * @param {Object} key
 */
function getDict(key) {
	if (store.state.dict.dicts[key]) {
		return store.state.dict.dicts[key]
	} else {
		return []
	}
}

/**
 * 获取字典值
 * 
 * @param {Object} key
 * @param {Object} val
 */
function getLabel(key, val) {
	const dict = getDict(key)
	if (dict.length > 0) {
		const obj = dict.find(item => item.value === val)
		if (obj) {
			return obj.label
		} else {
			return ''
		}
	} else {
		return ''
	}
}

const DictUtil = {
	getDict,
	getLabel
}

export default DictUtil